Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Launchpad Architecture Refactoring #451

Merged
merged 67 commits into from
Jan 19, 2025
Merged

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Dec 26, 2024

Description

This PR introduces a comprehensive refactoring of the Launchpad contract architecture, focusing on optimizing reward calculations and improving data structure efficiency. The main goals are to reduce computational overhead, enhance gas efficiency, and improve the overall maintainability of the codebase.

Key Changes

Architectural Improvements

  • Separated business logic into pure functions for better testability
  • Introduced domain-specific types for better data organization (e.g., ProjectInput, ProjectTierInfo, DepositState)
  • Improved error handling by returning errors in internal functions while maintaining panic in public interfaces
  • Implemented proper pointer handling for uint256 operations using Clone()

Code Structure

  • Split large functions into smaller, focused functions with single responsibilities
  • Maintained public function signatures for backward compatibility
  • Reduced code duplication through reusable helper functions

Major Refactored Components

Project Management (launchpad_init.gno -> launchpad.gno)

  • Added validation layer with validateProjectInput
  • Separated tier creation logic into createTier
  • Improved project creation workflow with clear steps

Reward Handling (launchpad_reward.gno -> reward.gno)

  • Separated reward validation and processing logic
  • Improved uint256 handling for calculations

Deposit Management (launchpad_deposit.gno)

  • Added DepositState for better state management
  • Separated deposit validation (validateDepositCollection)
  • Improved deposit processing with clear error handling
  • Added proper indexing management

Simplified and More Organized Types

  • Introduced new type groupings for better data organization and reduced memory footprint:
    • TimeInfo: Consolidated height and timestamp pairs
    • ProjectStats: Grouped project statistics fields
    • RefundInfo: Consolidated refund-related fields

Project Structure Improvements

  • Refactored Project struct for better maintainability:
    • Replaced individual tier fields with a map-based structure (map[uint64]Tier)
    • Introduced tiersRatios map for cleaner ratio management
    • Grouped time-related fields using TimeInfo
    • Consolidated project statistics into ProjectStats
    • Grouped refund information into RefundInfo

Benefits of New Structure

  • Reduced code duplication in time-related fields
  • Better encapsulation of related data
  • More flexible tier management through map structure
  • Improved readability and maintainability
  • Reduced potential for errors in related field updates
  • More intuitive grouping of related fields

Memory Optimization

  • Reduced struct size through better field organization
  • Improved memory locality for related fields
  • More efficient handling of optional fields

Performance Considerations

  • Maintained O(1) access for critical operations
  • Reduced memory allocations where possible
  • Optimized struct sizes and memory layout

Future Improvements

  • Additional caching strategies

@notJoon notJoon changed the title refactor: launchpad refactor: Launchpad Architecture Refactoring Jan 2, 2025
@notJoon notJoon self-assigned this Jan 2, 2025
@notJoon notJoon marked this pull request as ready for review January 4, 2025 04:11
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/deposit.gno Show resolved Hide resolved
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/deposit.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/launchpad.gno Outdated Show resolved Hide resolved
launchpad/reward.gno Outdated Show resolved Hide resolved
launchpad/reward.gno Outdated Show resolved Hide resolved
r3v4s
r3v4s previously approved these changes Jan 6, 2025
@r3v4s r3v4s self-requested a review January 6, 2025 06:31
Copy link
Member

@r3v4s r3v4s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left few comments.

onlyhyde
onlyhyde previously approved these changes Jan 19, 2025
jinoosss
jinoosss previously approved these changes Jan 19, 2025
@onlyhyde onlyhyde dismissed stale reviews from jinoosss and themself via 38e31c7 January 19, 2025 19:07
@onlyhyde onlyhyde requested review from onlyhyde and jinoosss January 19, 2025 19:08
@notJoon notJoon merged commit 5cef697 into main Jan 19, 2025
1 of 2 checks passed
@notJoon notJoon deleted the refactor-launchpad branch January 19, 2025 19:08
moul pushed a commit that referenced this pull request Jan 20, 2025
* chore: remove function prefix from panic msg

* save

* save

* test: reward handler

* feat: deposit handler

* fix error

* reward distributor

* update test

* update docs

* fix

* refactor deposit, launchpad, reward

* reduce type size

* fix rpc

* refactor: error message

* fix

* fix

* test: json builder

* update deposit test

* test: reward

* fix

* add launchpad new logic

* catch compile errors

* fix: weird interface nil error

* refactor: reward empty

* fix: when collecting deposit, check claimable Time
(not ended height)

* test: fix

* test: fix MultipleDeposit

* test: fix TestValidateRewardCollection
- no such error

* resolved some comments

* remove  unnecessary things

* remove unnecessary json builder functuion

* refactor: event message

* update launchpad test

* fix: reward_calculation

* remove dummy_test file

* additional refactor for `CreateProject`

* fix: prevent throwing nil deref error in `CollectRewardByProjectId`

* validate json creation

* save

* fix fee protocol

* remove: token register

* fix compile error for reward03 test

* paritally fix: `CollectRewardByProjectId` -- update `RewardState`

* fix

* refactor: clean code and add comments for functions

* test: reward calculation

* update reward test

* refactor: deposit refactoring

* refactor: create project

* refactor: deposit

* refactor: reward by projectId

* refactor: deposit and reward

* refactor: left reward

* refactor: reward test

* refactor: move test code into test folder

* refactor: remove unused code

* chore: remove some comments

* chore: remove comments

* remove: hard-coded string

* remove: invalid comments

* fix: check duplicate collect gns

---------

Co-authored-by: 0xTopaz <[email protected]>
Co-authored-by: mconcat <[email protected]>
Co-authored-by: n3wbie <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants